﻿using ControleRepresentante.Data.Catalogs;
using ControleRepresentante.Data.Helpers;


namespace ControleRepresentante.Data.CatalogSteps
{
    internal class CreateIndexColumnsPreferenceCatalogStep : CatalogStepBase<ControleRepresentanteCatalogStepTypes>
    {
        protected override ControleRepresentanteCatalogStepTypes CatalogStepType
        {
            get { return ControleRepresentanteCatalogStepTypes.CreateIndexColumnsPreference; }
        }

        public override void Execute(IDataAccess dataAccess)
        {
            CatalogStepHelper catalogStepHelper = new CatalogStepHelper(dataAccess);
            
            catalogStepHelper.CreateTable("IndexColumnsPreference")
                .AddColumn("UserId", ColumnType.Guid, false, false)
                .AddForeignKey("UserId", "SystemUser")
                .AddColumn("Area", ColumnType.ShortNumeric, false, false);

            catalogStepHelper.CreateTable("BuiltInIndexColumnPreference")
                .AddColumn("IndexColumnsPreferenceId", ColumnType.Guid, false, false)
                .AddForeignKey("IndexColumnsPreferenceId", "IndexColumnsPreference");

            catalogStepHelper.CreateTable("AttributeIndexColumnPreference")
                .AddColumn("IndexColumnsPreferenceId", ColumnType.Guid, false, false)
                .AddForeignKey("IndexColumnsPreferenceId", "IndexColumnsPreference")
                .AddColumn("AttributeId", ColumnType.Guid, false, false)
                .AddForeignKey("AttributeId", "Attribute");
        }
    }
}
